package com.hex.liyue.usermodule.presenter;

import com.hex.liyue.LiYueApplication;
import com.hex.liyue.commonmodule.manager.HttpManager;
import com.hex.liyue.commonmodule.manager.UserManager;
import com.hex.liyue.commonmodule.net.ResponseListener;
import com.hex.liyue.commonmodule.utils.SPUtil;
import com.hex.liyue.usermodule.bean.MyFriendsResultBean;
import com.hex.liyue.usermodule.bean.MyUpLinesResultBean;
import com.hex.liyue.usermodule.fragment.MeFragment;

/**
 * Created by $cmm on 2016/6/21.
 * <p/>
 * 我的线下小伙伴的业务类
 */
public class FriendsPresenter {
    private IFriendsView iFriendsView;

    public FriendsPresenter(IFriendsView iFriendsView) {
        this.iFriendsView = iFriendsView;
    }

    /**
     * 获取我的上线，下线小伙伴
     */
    public void myFrendis() {
        iFriendsView.showLod("加载中...");
        HttpManager.getInstance().myFrendis(
                UserManager.getUserId(),
                1,
                5,
                new ResponseListener<MyFriendsResultBean>() {
                    @Override
                    public void onSuccess(MyFriendsResultBean myFriendsResultBean) {
                        iFriendsView.closeLod();
                        iFriendsView.setAdapter(myFriendsResultBean);
                    }

                    @Override
                    public void onFailure(String responseresult) {
                        iFriendsView.closeLod();
                        iFriendsView.showT(responseresult);
                    }
                }

        );
    }

    /**
     * 填写上线邀请码
     */
    public void offLinesMyFrendis() {
        iFriendsView.showLod("加载中...");
        HttpManager.getInstance().offLinesMyFrendis(
                UserManager.getUserId(),
                iFriendsView.getInviteCode(),
                new ResponseListener<MyUpLinesResultBean>() {
                    @Override
                    public void onSuccess(MyUpLinesResultBean myUpLinesResultBean) {
                        SPUtil.putString(LiYueApplication.getInstance(),"success","success");
                        MeFragment.mFlag="success";
                        iFriendsView.closeLod();
                        iFriendsView.setAdapter(myUpLinesResultBean);
                    }

                    @Override
                    public void onFailure(String responseresult) {
                        iFriendsView.closeLod();
                        iFriendsView.showT(responseresult);
                    }
                });
    }
}
